//
//  LoginViewController.m
//  
//
//  Created by admin on 2017/3/14.
//
//

#import "LoginViewController.h"
#import "RegisterViewController.h"
#import <UMSocialCore/UMSocialCore.h>
#import "LoginView.h"

@interface LoginViewController ()

@property (nonatomic , strong)LoginView *Views;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    [self.view addSubview:[self Views]];
    
    
}



-(LoginView *)Views{
    
    if (!_Views) {
        _Views = [[LoginView alloc] initWithFrame:self.view.frame];
        [_Views.eyeBtn addTarget:self action:@selector(eyeBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_Views.losepsdBtn addTarget:self action:@selector(losePsd:) forControlEvents:UIControlEventTouchUpInside];
        [_Views.loginBtn addTarget:self action:@selector(loginBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_Views.wxBtn addTarget:self action:@selector(wxBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_Views.qqBtn addTarget:self action:@selector(qqBtn:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _Views;
}

#pragma mark-微信第三方登录
-(void)wxBtn:(UIButton *)sender{
    
    [self getUserInfoForPlatform:UMSocialPlatformType_WechatSession];
}


#pragma mark-qq第三方登录
-(void)qqBtn:(UIButton *)sender{
    
    [self getUserInfoForPlatform:UMSocialPlatformType_QQ];
    
}

- (void)getUserInfoForPlatform:(UMSocialPlatformType)platformType
{
    [[UMSocialManager defaultManager] getUserInfoWithPlatform:platformType currentViewController:self completion:^(id result, NSError *error) {
        
        if (error) {
            
            SLog(@"error:%@",error);
            
        } else {
        
        
        SLog(@"result:%@",result);
        UMSocialUserInfoResponse *resp = result;
        
        // 第三方登录数据(为空表示平台未提供)
        // 授权数据
        SLog(@" uid: %@", resp.uid);
        SLog(@" openid: %@", resp.openid);
        SLog(@" accessToken: %@", resp.accessToken);
        SLog(@" refreshToken: %@", resp.refreshToken);
        SLog(@" expiration: %@", resp.expiration);
        
        // 用户数据
        SLog(@" name: %@", resp.name);
        SLog(@" iconurl: %@", resp.iconurl);
        SLog(@" gender: %@", resp.gender);
        
        // 第三方平台SDK原始数据
        SLog(@" originalResponse: %@", resp.originalResponse);
        }
    }];
}



#pragma mark-登录
-(void)loginBtn:(UIButton *)sender{
    
    
    
}

#pragma mark-忘记密码
-(void)losePsd:(UIButton *)sender{
    
    
}


#pragma mark-显示密码
-(void)eyeBtn:(UIButton *)sender{
    
    sender.selected=!sender.selected;
    if(sender.selected){
        
        
//        //避免明文/密文切换后光标位置偏移
//        self.psdTextField.enabled = NO;    // the first one;
        self.psdTextField.secureTextEntry = NO;
//        sender.selected = !sender.selected;
//        self.psdTextField.enabled = YES;  // the second one;
        [self.psdTextField becomeFirstResponder];
        
    }else{
        
        self.psdTextField.secureTextEntry = YES;
        [self.psdTextField becomeFirstResponder];

    }
}

- (void)viewWillAppear:(BOOL)animated{
    
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(PushRegister:)];
    
    UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回"] style:UIBarButtonItemStylePlain target:self action:@selector(backVC:)];
    self.navigationItem.leftBarButtonItem = leftBtn;
    self.navigationItem.rightBarButtonItem = rightBtn;
    leftBtn.tintColor = [UIColor whiteColor];
    rightBtn.tintColor = [UIColor whiteColor];
    
    //设置导航栏背景图片为一个空的image，这样就透明了
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    
    //去掉透明后导航栏下边的黑边
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    
}

- (void)viewWillDisappear:(BOOL)animated{
    
    //    如果不想让其他页面的导航栏变为透明 需要重置
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}

#pragma mark-返回上一级
-(void)backVC:(UIButton *)sender{
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

#pragma mark-注册
-(void)PushRegister:(UIButton *)sender{
    
    RegisterViewController *vc = [[RegisterViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
